import requests


def create_ins():
    url = "http://localhost/noAuth/createK8sInstanceOne"
    data = {
        "name": "busy03",
        "cluster": "bigdevops",
        "image": "busybox",
        "k8SAppID": 1,
        "cpuRequest":"0.04",
        "labels":["k223=v3"],
    }
    res = requests.post(url, json=data)
    print(res.status_code)
    print(res.text)
    print(res.json())

def update_ins():
    url = "http://localhost/noAuth/updateK8sInstanceOne"
    data = {
        "name": "busy01",
        "cluster": "bigdevops",
        "image": "busybox",
        "k8SAppID": 1,
        "id": 1,
        "cpuRequest":"0.07",

    }
    res = requests.post(url, json=data)
    print(res.status_code)
    print(res.text)
    print(res.json())

def delete_ins():
    url = "http://localhost/noAuth/batchDeleteK8sInstance"
    data = {
        "cluster": "bigdevops",
        "ids":[1,2],

    }
    res = requests.delete(url, json=data)
    print(res.status_code)
    print(res.text)
    print(res.json())

def restart_ins():
    url = "http://localhost/noAuth/batchRestartK8sInstance"
    data = {
        "cluster": "bigdevops",
        "ids":[3],

    }
    res = requests.post(url, json=data)
    print(res.status_code)
    print(res.text)
    print(res.json())


def get_ins():
    url = "http://localhost/noAuth/getK8sInstanceByApp"
    data = {
        "cluster": "bigdevops",
        "app":"k8s-app-0",

    }
    res = requests.get(url, params=data)
    print(res.status_code)
    print(res.text)
    # print(res.json())


def update_app():
    url = "http://localhost/noAuth/updateK8sAppOne"

    data = {
        "cluster": "bigdevops",
        "id": 1,
        "cpuRequest":"0.07",
        "labels": ["add=001"],
        "name":"k8s-app-0",
        "namespace":"default",
        "UserID":1,
        "treeNodeId":5,
        "portJson": '''[{"name":"http","protocol":"TCP","port":80,"targetPort":80}]''',
        "volumeJson": '''[{"type":"hostPath","name":"log","mountPath":"/log","subPath":"sub","pvcName":"","cmName":"","hostPathPath":"/data/k8s-app-0","hostPathType":"DirectoryOrCreate"},{"type":"configMap","name":"cm","mountPath":"/cm","subPath":"","pvcName":"","cmName":"cm-demo01","hostPathPath":"","hostPathType":""}]''',
        "commands": ["sh","-c","echo The app is running! && sleep infinity"],


    }
    res = requests.post(url, json=data)
    print(res.status_code)
    print(res.text)
    print(res.json())

# create_ins()
# update_ins()
# delete_ins()

# restart_ins()
# get_ins()
update_app()